package org.jjj.car.service.impl;

import org.jjj.car.domain.CarResources;
import org.jjj.car.mapper.CarResourcesMapper;
import org.jjj.car.service.ICarResourcesService;
import org.jjj.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiangjianjun
 * @since 2022-11-03
 */
@Service
public class CarResourcesServiceImpl extends BaseServiceImpl<CarResources> implements ICarResourcesService {
    @Autowired
    private CarResourcesMapper carResourcesMapper;
    /**
     * 以为车辆信息和资源是一对一关系
     * 所以采用先删除直接新增的方式来保存新增和修改资源的方法
     * @param carResources
     */
    @Override
    @Transactional
    public void saveCarResources(CarResources carResources) {
        //先删除
        carResourcesMapper.deleteByCarId(carResources.getCarId());
        //再新增资源数据到数据库中，每次保证一辆车只有一份资源数据
        super.add(carResources);
    }
}
